/*
 * Copyright© 2013-2018 YZTC 
 * Author zhenghl 
 * 本公司保留所有下述内容的权利; 
 * 本内容为保密信息，仅限本公司内部使用; 
 * 非经本公司书面许可，任何人不得外泄或用于其他目的; 
*/
package com.wxmp.wxcms.service.impl; 
import com.wxmp.core.util.DateUtil; 
import com.wxmp.core.util.StringUtil; 
import com.wxmp.wxapi.process.MpAccount;
import com.wxmp.wxapi.process.WxApiPay;
import com.wxmp.wxcms.domain.RedGroupPack;
import com.wxmp.wxcms.domain.RedPack;
import com.wxmp.wxcms.service.RedpackService;
 
import org.springframework.stereotype.Service;
import java.util.Date;

/**
 *
 * @author hermit
 * @version 2.0
 * @date 2018-04-17 10:54:58
 */
@Service
public class RedpackServiceImpl  implements RedpackService{ 
    @Override
    public boolean postRedpack(String certFile,RedPack bean,MpAccount mpAccount) throws Exception {
            bean.setMch_billno(mpAccount.getMchId()+DateUtil.changeDateTOStr2(new Date())+StringUtil.getRandomLengthString(10));
            bean.setNonce_str(StringUtil.getRandomLengthString(32));
            bean.setWxappid(mpAccount.getAppid());
            bean.setMch_id(mpAccount.getMchId());
            bean.setSend_name(mpAccount.getMchName());
            String result = new WxApiPay().doSendredpack(certFile, mpAccount.getMchPwd(),mpAccount.getMchSecret(), bean);
            return true;
    }

    @Override
    public boolean postedGroupPack(String certFile,RedGroupPack bean,MpAccount mpAccount) throws Exception {
        bean.setMch_billno(mpAccount.getMchId()+DateUtil.changeDateTOStr2(new Date())+StringUtil.getRandomLengthString(10));
        bean.setNonce_str(StringUtil.getRandomLengthString(32));
        bean.setWxappid(mpAccount.getAppid());
        bean.setMch_id(mpAccount.getMchId());
        bean.setSend_name(mpAccount.getMchName());
        //bean.setSign(SignUtil.getSignString(BeanUtil.getAllFields(bean, RedPack.class),mpAccount.getMchSecret()));
        String result = new WxApiPay().doSendredpack(certFile, mpAccount.getMchPwd(), mpAccount.getMchSecret(),bean);
        return true;
    }
	 
}
